package com.weipai.demo.service.impl;

import com.weipai.demo.enums.RetCode;
import com.weipai.demo.mapper.base.PushMessagesMapper;
import com.weipai.demo.model.PushNews;
import com.weipai.demo.service.JiguangPushService;
import com.weipai.demo.util.JpushClientUtil;
import com.weipai.demo.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: 赵项阳
 * @Date: 2019/6/15 18:26
 * @Version 1.0
 */
@Service
public class JiguangPushServiceImpl implements JiguangPushService {
    @Autowired
    PushMessagesMapper pushMessagesMapper;

    @Override
    public Response pushMessage(String title, String message) {
        Response response = new Response();
        PushNews pushNews = new PushNews();
        pushNews.setMessage(message);
        pushNews.setTitle(title);
        int i = pushMessagesMapper.insertSelective(pushNews);
        if (i > 0) {
            /*Jpush jpush=new Jpush();
            Map<String, String> map=new HashMap<>();*/
            //jpush.push(title,message,"" , Audience.all(),map);
            JpushClientUtil.sendToAllAndroid("",title,message,"");
            response.setCode(RetCode.SUCCESS);
        }else {
            response.setCode(RetCode.REQUEST_ERROR);
        }


        return response;
    }
}
